<template>
  <div class="app-container">
    <el-descriptions :column="1" class="margin-top" title="订单详情" border>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          轮播图详情
        </template>
        {{ advert.detail }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          轮播图排序
        </template>
        {{ advert.position }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          商品名称
        </template>
        {{ product.name }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          起始时间
        </template>
        {{ advert.beginTime }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          结束时间
        </template>
        {{ advert.endTime }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-shopping-cart-2"/>
          封面
        </template>
        <img :src="advert.image" alt="advert.detail" height="400px">
      </el-descriptions-item>

    </el-descriptions>
  </div>
</template>
<script>
import advert from '@/api/mall/advert'
import product from '@/api/mall/product'
export default {
  data() {
    return {
      product: {},
      advert: {
        image: '',
        sort: 1 },
      options: {}
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      if (this.$route.params && this.$route.params.id) {
        const id = this.$route.params.id
        this.getAdvert(id)
      } else {
        this.advert = {}
        this.product = {}
      }
    },
    getAdvert(id) {
      advert.getAdvert(id)
        .then(response => {
          this.advert = response.data.advert
          this.getProduct(this.advert.productId)
        })
    },
    getProduct(id) {
      product.getProduct(id)
        .then(response => {
          this.product = response.data.product
        })
    }
  }
}
</script>
